//
//  ThirdViewController.m
//  UI - 豆瓣
//
//  Created by dllo on 15/10/27.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "ThirdViewController.h"
#import "ThirdViewCell.h"
#import "AppTools.h"
#import "Cinema.h"
#import "MBProgressHUD.h"

@interface ThirdViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic , retain)UITableView *myTableView;
@property(nonatomic, retain)NSMutableArray *bigArray;
@property(nonatomic, retain)MBProgressHUD *hub;


@end

@implementation ThirdViewController
- (void)dealloc
{
    [_bigArray release];
    [_myTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"影院";
    self.myTableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    [self.myTableView release];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.myTableView registerClass:[ThirdViewCell class] forCellReuseIdentifier:@"cell"];
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"@我知道你急@";
    self.bigArray = [[NSMutableArray alloc] init];
    NSString *str = @"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/cinemalist.php";
    [AppTools getWithName:str Block:^(id result) {
        NSMutableDictionary *dic = result;
        NSMutableDictionary *resultDic = [dic objectForKey:@"result"];
        NSMutableArray *array = [resultDic objectForKey:@"data"];
        for (NSMutableDictionary *dic in array) {
            Cinema *cinema = [[Cinema alloc] init];
            [cinema setValuesForKeysWithDictionary:dic];
            [self.bigArray addObject:cinema];
            [cinema release];
        }
        
        [self.myTableView reloadData];
        [self.hub hide:YES];
    }];
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return self.bigArray.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    NSString *filePath = @"cell";
    ThirdViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:filePath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    Cinema *cinema = [self.bigArray objectAtIndex:indexPath.row];
    cell.cinema = cinema;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 138;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
